<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>预约接种管理</title>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="bootstrap/js/bootstrap.js" type="text/javascript"></script>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <script src="layui/layui.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css">
    <style>
        body{
            margin-top: 0;
            padding: 30px;
        }
    </style>
</head>
<body>
<ol class="breadcrumb">
    <li><a href="/mainbg">主页</a></li>
    <li><a href="#">预约接种管理</a></li>
</ol>
<div id="pointInfo" class="container-fluid">
    <div class="panel panel-success">
        <div class="panel-heading">接种疫苗查询</div>
        <div class="panel-body">
            <form id="formId" class="form-inline" action="findAllISiteAndVacc">
                <input type="hidden" name="pageNo" id="pageNo" th:value="${pageInfo.pageNum}" >
                <input type="hidden" name="pageSize" id="pageSize" th:value="${pageInfo.pageSize}">
                <input type="hidden" id="pageTotal" th:value="${pageInfo.total}">
                <div class="form-group">
                    <label for="nameId">疫苗名称</label>
                    <input style="width: 156px;" type="text" name="vaccinesname" class="form-control" id="nameId" placeholder="请输入疫苗名称关键字">
                </div>
                <div class="form-group">
                    <label for="nameId">接种点</label>
                    <input style="width: 156px;" type="text" name="inoculationname" id="inoculationnameId" class="form-control" placeholder="请输入接种点关键字">
                </div>
                <div class="form-group">
                    <label for="nameId">疫苗厂商</label>
                    <input style="width: 156px;" type="text" name="manufactor" class="form-control"  placeholder="请输入疫苗厂商关键字">
                </div>
                <div class="form-group">
                    <label for="timeId">开始接种时间</label>
                    <input type="text" name="starttime" class="form-control" id="timeId" placeholder="yyyy-MM-dd HH:mm:ss">
                </div>
                <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>查询</button>
            </form>
        </div>
        <table class="table table-bordered table-striped table-hover" style="margin-top: 10px">
            <thead>
            <tr class="info">
                <th>接种点编号</th>
                <th>疫苗名称</th>
                <th>疫苗厂商</th>
                <th>剩余数量</th>
                <th>接种点名称</th>
                <th>开始接种时间</th>
                <th>结束接种时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="iSiteAndVacc:${iSiteAndVaccList}">
                <td th:text="${iSiteAndVacc.id}"></td>
                <td th:text="${iSiteAndVacc.vaccinesname}"></td>
                <td th:text="${iSiteAndVacc.manufactor}"></td>
                <td th:text="${iSiteAndVacc.inventory}"></td>
                <td th:text="${iSiteAndVacc.inoculationname}"></td>
                <td th:text="${#dates.format(iSiteAndVacc.starttime, 'yyyy-MM-dd HH:mm:ss')}"></td>
                <td th:text="${#dates.format(iSiteAndVacc.endtime, 'yyyy-MM-dd HH:mm:ss')}"></td>
                <td>
                    <button th:if="${iSiteAndVacc.inventory>0}" type="button" class="btn btn-success btn-sm" data-toggle="modal" th:onclick="addReservation('[[${iSiteAndVacc}]]')" data-target="#myUpdate">
                        <span class="glyphicon glyphicon-ok">预约</span></button>
                    <button th:if="${iSiteAndVacc.inventory==0}" disabled type="button" class="btn btn-danger btn-sm" title="不可预约">
                        <span class="glyphicon glyphicon-remove">预约</span></button>
                </td>
            </tr>
            </tbody>
        </table>
        <div id="pageDemo"></div>
    </div>
    <div class="modal fade" id="myUpdate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel2">预约接种</h4>
                </div>
                <form id="addReservationForm">
                    <div class="modal-body">
                        <input type="hidden" name="ivId" id="ivId">
                        <input type="hidden" name="vaccinesid" id="vaccinesid">
                        <input type="hidden" name="inoculationid" id="inoculationid">
                        <input type="hidden" name="userid" th:value="${session.user.id}">
                        <input type="hidden" name="status" value="1">
                        <div class="form-group form-inline">
                            <label style="width: 70px;">疫苗名称</label>
                            <input type="text" id="vaccinesname" name="vaccinesname" readonly class="form-control" placeholder="请输入医院名称">
                        </div>
                        <div class="form-group form-inline">
                            <label>接种点名称</label>
                            <input type="text" id="inoculationname" name="inoculationname" readonly class="form-control" placeholder="请输入医院详细地址">
                        </div>
                        <div class="form-group form-inline">
                            <label>开始时间</label>
                            <input type="text" id="startTimeU" name="starttime" class="layui-input" readonly pattern="yyyy-MM-dd HH:mm:ss" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                        <div class="form-group form-inline">
                            <label>结束时间</label>
                            <input type="text" id="endTimeU" name="endtime" class="layui-input" readonly pattern="yyyy-MM-dd HH:mm:ss" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-warning" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success" data-dismiss="modal" onclick="addReservation2()">确定预约</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="js/layuiDateForMate.js"></script>
<script type="text/javascript">
    function timeOutReflush() {
        setTimeout(function () {
            window.location.href='findAllISiteAndVacc?pageNo='+$('#pageNo').val()+'&pageSize='+$('#pageSize').val();
        },1500);
    }
    function addReservation(iSiteAndVacc) {   //弹出修改框并插入数据
        console.log(iSiteAndVacc);
        var iSiteAndVacc=eval("("+iSiteAndVacc+")");   //将json转化成对象
        console.log(typeof iSiteAndVacc);
        $("#ivId").val(iSiteAndVacc.id);
        $("#vaccinesid").val(iSiteAndVacc.vaccinesid);
        $("#inoculationid").val(iSiteAndVacc.inoculationid);
        $("#vaccinesname").val(iSiteAndVacc.vaccinesname);
        $("#inoculationname").val(iSiteAndVacc.inoculationname);
        $("#startTimeU").val(translaDate(iSiteAndVacc.starttime));
        $("#endTimeU").val(translaDate(iSiteAndVacc.endtime));
    }
    function addReservation2() {
        $.ajax({
            url: '/addReservation',
            type: 'post',
            data: $("#addReservationForm").serialize(),
            success: function (result) {
                console.log(result);
                if(result=='SUCCESS'){   //修改成功
                    layer.msg("预约成功",{icon:1});
                    timeOutReflush();
                }else{   //登录失败
                    layer.alert('预约失败,请注意时间是否在可预约时间段!',{icon:2});
                }
            }
        });
        return false;
    }
</script>
<script type="text/javascript">
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
        var form = layui.form;
        var layer = layui.layer;
        var util = layui.util;

        let pageNo=parseInt($('#pageNo').val());
        let pageSize=parseInt($('#pageSize').val());
        let pageTotal=parseInt($('#pageTotal').val());

        //完整功能
        laypage.render({
            elem: 'pageDemo'
            ,count: pageTotal
            ,curr: pageNo
            ,limit: pageSize
            ,limits: [5,10,20,30,50]
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            ,jump: function(obj,first){
                console.log(obj);
                if(!first){
                    //do something
                    $('#pageNo').val(obj.curr);
                    $('#pageSize').val(obj.limit);
                    $('#formId').submit();
                }
            }
        });
    });
</script>
</body>
</html>